/**
* @namespace
* Maintains a collection of BizObj types (JavaScript classes) that it uses to service requests to
* create BizObj and BizObj List objects.
* @Depends feature.bizobj.js
* @meta-type static class
*/
ksg.App.bizObjMgr = {
	/**
	* Given a bizobj type name and plain javascript object containing values for the new bizobj,
	* this will create the given type.  If the plain javascript object contains a key named
	* _type it will override the typeName provided and try to use the value of _type for the 
	* new bizobj type.
	*
	* <p>Typically, if json wont contain _type on every object, which would bloat the total size transmitted.
	* However there are special cases such as a field of a bizobj is a hetrogenous map of objects and
	* as such each object in that particular map is providing a _type to specify what it is.</p>
	*
	* <p>When the actual bizobj structure is generated from a SCS feature xml, then there should be a good
	* understanding of what objects are contained within the structure.</p>
	* @param {String} typeName The bizobj type name to create a new bizobj from.
	* @param {Object} bizObj A plain object that contains values that should be used to initialize the bizobj with.
	* This is particularly useful when getting data back as plain JSON and then using that to create bizobjs.
	*/
	create: function(typeName, bizObj) {
		if(bizObj == null)
			bizObj = {};
		
		var bizObjType = null;
		if(typeName)
			bizObjType = ksg.bizobj.bizObjTypes[typeName];
		
		var obj = bizObj;
		if("_type" in obj) {
			var _type = ksg.bizobj.bizObjTypes[obj["_type"]];
			if(_type)
				bizObjType = _type;
		}
		
		if(bizObjType)
			obj = new bizObjType(bizObj);

		return obj;
	},
	
	/**
	* Given a bizobj type name and a regular javascript array of objects such as that created from JSON,
	* this will create a bizobj list of the given type.
	* @param {String} typeName The bizobj type name to create a new bizobj list from.
	* @param {Object} bizObjs A plain javascript array of objects that contains values that should be used to 
	* initialize each bizobj in the list with.
	* This is particularly useful when getting data back as plain JSON and then using that to create bizobjs.
	*/
	createList: function(typeName, bizObjs) {
		var list = {
			bizObjs: bizObjs,
			typeName: typeName
		};
		list.prototype = ksg.bizobj.BizObjList;
		if(bizObjs)
			for(var i in bizObjs)
				bizObjs[i] = this.create(typeName, bizObjs[i]);
		
		return list;
	}
};